package com.tencreat.mall.controller.app;

import com.tencreat.common.core.HttpResult;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.domain.mall.MallPaySetting;
import com.tencreat.service.mall.IMallPaySettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 支付设置Controller
 *
 * @Author tencreat
 * @Company: 深圳腾创互联科技有限公司
 * @link: https://tencreat.com
 * @Date 2022-07-07
 */
@Api(tags="支付设置api")
@RestController
@RequestMapping("/api/mall/pay-setting")
public class MallPaySettingApiController extends BaseController {
    @Autowired
    private IMallPaySettingService mallPaySettingService;

    @ApiOperation(value="查询支付设置列表")
    @ApiImplicitParam(value = "类型，0|藏品购买,1|余额充值", name = "type")
    @GetMapping("/list")
    public HttpResult<List<MallPaySetting>> list(Integer type) {
        List<MallPaySetting> list = mallPaySettingService.lambdaQuery().eq(MallPaySetting::getType, type).orderByAsc(MallPaySetting::getSort).list();
        list.forEach(item -> {
            if (item.getCompany() != null) {
                item.setCompanyValue(item.getCompany().getValue());
            }
            if (item.getPayType() != null) {
                item.setPayTypeValue(item.getPayType().getValue());
            }
        });
        return HttpResult.ok(list);
    }

}
